package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    // 根据类型和时间统计用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM `tb_log` WHERE TYPE = #{type} AND log_time = #{time}")
    public Integer findTypeAndTime(@Param("type") String type, @Param("time") String time);

    // 根据时间统计用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM `tb_log` WHERE log_time = #{time}")
    public Integer findByTime(String time);

    // 根据昨天和今日统计用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM `tb_log` WHERE log_time =#{today} \n" +
            "AND user_id IN(SELECT DISTINCT user_id FROM `tb_log` WHERE TYPE = '0102' AND log_time = #{yesterday})")
    public Integer findByTodayAndYesterday(@Param("today") String today, @Param("yesterday") String yesterday);
}